package com.liustar.oplog.admin.controller;


import com.liustar.common.response.ResultMessage;
import com.liustar.oplog.annotation.OpLog;
import com.liustar.oplog.constant.OpTypeConst;
import com.liustar.oplog.model.OperationLog;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.logging.Logger;


@RequestMapping(value = "/test")
@RestController
public class TestController {

    private final Logger logger = Logger.getLogger(this.getClass().getName());

    @RequestMapping(value = "/test_log")
    @OpLog(opType = OpTypeConst.SEARCH, opDesc = "测试日志记录")
    ResultMessage testLog(HttpServletRequest request, OperationLog operationLog) {
        logger.info("进入test_log");
        operationLog.setOperationContent("操作内容");
        operationLog.setUsername("");
        return ResultMessage.newSuccess().putData("testLog", "");
    }

    @RequestMapping(value = "/test_login")
    @OpLog(opType = OpTypeConst.LOGIN, opDesc = "登录")
    ResultMessage testLogin(HttpServletRequest request, OperationLog operationLog) {
        String username = request.getParameter("username");
        request.getSession().setAttribute("username", username);
        logger.info("进入test_log");
        operationLog.setOperationContent("测试写日志");
        return ResultMessage.newSuccess().putData("testLogin", username);
    }
}
